# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = 'restructuredtext en'

from ... import pilelib as stack
from ...gamelib import info as gi
from ...packlib import info as cs
from .. import katzenschwanz

GT, SL = gi.GT, gi.SL
Wrap = stack.StackWrapper


class Labyrinth(cs.HexA_Deck, katzenschwanz.DerKatzenschwanz):
    """
    Finish 2 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layout.CatsTailLayout
        - row [9 horz S reserve, vert - horz offset]
        - reserve [8 N, no offset]
        - talon [1 SW foundation, no offset]
        - foundation [10 over 2 col E, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.InitialDealTalon

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stack.SS_Foundation

        Build in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stack.AC_RowStack (base_rank=GAP)

        Init all cards with 0x10 start pile. Build down in rank by alt
        color. Play seq. Base none.

      _reserve_ : pysollib.stack.Stack
        .. pysollib.stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x1a0b7, name='Hex Labyrinth',
                    category=cs.TYPE_HEXADECK, game_type=(GT.FREECELL |
                    GT.OPEN), decks=2, skill_level=SL.MOSTLY_SKILL,
                    version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    def _start(self):
        self._play_sound('deal')
        i = 0
        while self.s['talon'].cards:
            if self.s['talon'].TOPCARD['rank'] == cs.x10:
                if self.s['rows'][i].cards:
                    i += 1
            self.s['talon'].dealRowAvail(rows=[self.s['rows'][i]], frames=4)


class Convolution(Labyrinth):
    """
    Finish 2 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. layout.CatsTailLayout

        - row [9 horz S reserve, vert - horz offset]
        - reserve [8 N, no offset]
        - talon [1 SW foundation, no offset]
        - foundation [10 over 2 col E, no offset]

      _talon_ : pysollib.stack.Stack
        .. stack.InitialDealTalon

      _waste_ : pysollib.stack.Stack
        .. stack.WasteStack

        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. stack.RK_RowStack (base_rank=GAP)

        Init all cards with 0x10 start pile. Build down in rank alone.
        Play seq. Base none.

      _reserve_ : pysollib.stack.Stack
        .. stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x1a0b6, name='Convolution', category=cs.TYPE_HEXADECK,
                    game_type=(GT.FREECELL | GT.OPEN), decks=2,
                    skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(stack.RK_RowStack, base_rank=cs.GAP)


class Snakestone(Convolution):
    """
    Finish 2 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. layout.CatsTailLayout

        - row [9 horz S reserve, vert - horz offset]
        - reserve [8 N, no offset]
        - talon [1 SW foundation, no offset]
        - foundation [10 over 2 col E, no offset]

      _talon_ : pysollib.stack.Stack
        .. stack.InitialDealTalon

      _waste_ : pysollib.stack.Stack
        .. stack.WasteStack

        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. stack.SS_RowStack (base_rank=GAP)

        Init all cards with 0x10 start pile. Build down in rank by same
        suit. Play seq. Base none.

      _reserve_ : pysollib.stack.Stack
        .. stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x1a0b8, name='Snakestone', category=cs.TYPE_HEXADECK,
                    game_type=(GT.FREECELL | GT.OPEN), decks=2,
                    skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(stack.SS_RowStack, base_rank=cs.GAP)


PROVIDES = [Convolution, Labyrinth, Snakestone]